<?php
class Backend_Logs_Controller extends Backend_Controller
{
	/**
	 * (non-PHPdoc)
	 * @see Backend_Controller::indexAction()
	 */
	public function indexAction()
	{      	
        $res = Resource::getInstance();    
	    $res->addJs('/js/app/system/crud/logs.js' , true , 1);
	    
	    $actions = array(array('id'=>'',$this->_lang->ALL));
	    
	    foreach (Model_Historylog::$actions as $k=>$v)
	    	$actions[] = array('id'=>$k,'title'=>$v);
	    
	    $res->addInlineJs('var logActions = '.json_encode($actions).';');
    }
    
    public function listAction()
    {
    	$logsModel = Model_Historylog::getInstance();
    	$pager = Request::post('pager', 'array', array());
    	$filter = Request::post('filter', 'array', array());
    	
    	$count = $logsModel->getCount($pager,$filter);
    	
    	$joins = array(array(
	 			'joinType'=>'joinLeft',
	  			'table' => array('u'=>Model_User::getInstance()->table()),
	 			'fields' => array('user'=>'name'),
	  			'condition'=> 'u.id = user_id'
	  	));
    	
    	$list = $logsModel->getListVc(
    		$pager, 
    		$filter, 
    		false ,
    		'*',
    		false,
    		false,
    		$joins
    	);
    	
    	if(!empty($list))
    		foreach ($list as &$value)
    			$value['type'] =Model_Historylog::$actions[$value['type']];
    	
    	
    	Response::jsonSuccess($list,array('count'=>$count));
    }
}